package cz.acies.genea.data.persist;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import cz.acies.data.persist.ModelObject;

public class GedProject extends ModelObject
{
	private static final long serialVersionUID = 4984216677191157243L;
	
	protected String name;
	protected Map<String, GedPerson> people;
	protected Map<String, GedFamily> families;
	
	public GedProject() {
		this("", new HashMap<String, Object>());
	}

	public GedProject(String id, Map<String, Object> data) {
		super(id, data);
	}
	
	// -----  -----------------------------------------------------------------
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}

	public Map<String, GedPerson> getPeople() {
		return people;
	}

	public void setPeople(List<GedPerson> list) {
		if (people == null) people = new LinkedHashMap<String, GedPerson>(); 
		else people.clear();
		for (GedPerson person : list) {
			addPerson(person);
		}
	}

	public void addPerson(GedPerson person) {
		if (people == null) people = new LinkedHashMap<String, GedPerson>();
		if (person == null || !person.hasId()) return;
		people.put(person.getId(), person);
	}

	// -----  -----------------------------------------------------------------
	
	public Map<String, GedFamily> getFamilies() {
		return families;
	}

	public void setFamilies(List<GedFamily> list) {
		if (families == null) families = new LinkedHashMap<String, GedFamily>(); 
		else families.clear();
		for (GedFamily family : list) {
			addFamily(family);
		}
	}

	public void addFamily(GedFamily family) {
		if (families == null) families = new LinkedHashMap<String, GedFamily>();
		if (family == null || !family.hasId()) return;
		families.put(family.getId(), family);
	}

}
